<template>
  <div class="sidebar">
    <div class="sidebar-logo" :class="collapse ? 'logo' : 'logo-active'"><img src="../../assets/img/logo.png"
        alt="img" /></div>
    <el-menu class="sidebar-el-menu" :default-active="onRoutes" :collapse="collapse" background-color="#001529"
      text-color="#bfcbd9" active-text-color="#20a0ff" unique-opened router>
      <template v-for="item in items">
        <template v-if="item.subs">
          <el-submenu :index="item.index" :key="item.index">
            <template slot="title">
              <i :class="item.icon"></i>
              <span slot="title">{{ item.title }}</span>
            </template>
            <template v-for="subItem in item.subs">
              <el-submenu v-if="subItem.subs" :index="subItem.index" :key="subItem.index">
                <template slot="title">{{ subItem.title }}</template>
                <el-menu-item v-for="(threeItem, i) in subItem.subs" :key="i" :index="threeItem.index">{{
      threeItem.title
    }}</el-menu-item>
              </el-submenu>
              <el-menu-item v-else :index="subItem.index" :key="subItem.index + 'a'">{{ subItem.title }}</el-menu-item>
            </template>
          </el-submenu>
        </template>
        <template v-else>
          <el-menu-item :index="item.index" :key="item.index">
            <i :class="item.icon"></i>
            <span slot="title">{{ item.title }}</span>
          </el-menu-item>
        </template>
      </template>
    </el-menu>
  </div>
</template>

<script>
import bus from '../common/bus';
export default {
  data() {
    return {
      collapse: false,

      items: [

        {
          icon: "el-icon-s-home",
          index: "home",
          title: "首页",

        }, {
          icon: "el-icon-s-comment",
          index: "1-1",
          title: "资产管理",
          subs: [
            {
              index: 'assetlist',
              title: '资产列表',
            },
            {
              index: 'assetin',
              title: '资产入库',

            },
            {
              index: 'assetinventory',
              title: '资产盘点',

            },
            {
              index: 'assetrepair',
              title: '资产报修',

            },
            {
              index: 'assetwaste',
              title: '资产报废',

            }
          ]

        }, {
          icon: "el-icon-s-finance",
          index: "1-2",
          title: "耗材管理",
          subs: [
            {
              index: 'consumablelist',
              title: '耗材列表',
            },
            {
              index: 'consumablein',
              title: '耗材入库',

            },
            {
              index: 'consumableout',
              title: '耗材出库',

            }
            // ,
            // {
            //   index: 'consumableinventory',
            //   title: '耗材盘点',

            // }
          ]

        }, {
          icon: "el-icon-s-marketing",
          index: "1-3",
          title: "资产统计",
          subs: [
            {
              index: 'generalsituation',
              title: '资产概况汇总',
            }, {
              index: 'classification',
              title: '资产分类汇总',
            },
            {
              index: 'location',
              title: '资产位置汇总',

            }
          ]
        }, {
          icon: "el-icon-setting",
          index: "1-4",
          title: "基础管理",
          subs: [
            {
              index: 'assetsource',
              title: '资产来源',
            },
            {
              index: 'reasonscrapping',
              title: '报废原因',

            },
            {
              index: 'consumableswarehouse',
              title: '耗材仓库',

            }
          ]
        }
      ]
    };
  },
  computed: {
    onRoutes() {
      return this.$route.path.replace('/', '');
    }
  },
  created() {
    // 通过 Event Bus 进行组件间通信，来折叠侧边栏
    bus.$on('collapse', (msg) => {
      this.collapse = msg;
      bus.$emit('collapse-content', msg);
    });

  },
  methods: {

  }
};
</script>

<style scoped>
.sidebar {
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  overflow-y: scroll;
}

.sidebar-logo {
  height: 100px;
  text-align: center;
  background-color: #001529;
  transition: width 0.3s ease-in-out;
}

.logo {
  width: 64px;
}

.logo-active {
  width: 250px;
}

img {
  display: block;
  width: 50px;
  margin: 0 auto;
  box-sizing: border-box;
  padding: 20px 0;
}

.sidebar::-webkit-scrollbar {
  width: 0;
}

.sidebar-el-menu:not(.el-menu--collapse) {
  width: 250px;
}

.sidebar>ul {
  height: 100%;
}
</style>
